package com.iman.manjusri.web.home;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJacksonJsonView;

import com.iman.manjusri.service.RmtpService;
import com.iman.manjusri.web.BaseController;

@Controller
@RequestMapping(value = "/home/*")
public class SpaceRmtpHomController extends BaseController {
	@Autowired
	private RmtpService rmtpService;

	@RequestMapping(value = "/rmtp")
	public ModelAndView resourceMore(HttpServletRequest request)
			throws Exception {

		int offset = NumberUtils.toInt(request.getParameter("offset"), 1);
		int counterPerPage = NumberUtils.toInt(request.getParameter("counterPerPage"), 12);
		

		ModelAndView view = null;
		if (request.getParameter("type") != null) {
			Map json = new HashMap();
			json.put("totalCount", 30);
			List results = new ArrayList();
			json.put("results", results);
			for (int i = offset; i < (offset+counterPerPage); i++) {
				Map result = new HashMap();
				result.put("_id", "id" + i);
				result.put("fileId", "fileId" + i);
				result.put("title", "title" + i);
				result.put("description", "description" + i);
				result.put("createTime", "createTime" + i);
				result.put("views", "views" + i);
				result.put("replies", "replies" + i);
				result.put("albumId", "albumId" + i);
				List listTags = new ArrayList();
				result.put("tags", listTags);
				results.add(result);
			}
			view = new ModelAndView(new MappingJacksonJsonView(), json);
		} else {
			view = new ModelAndView("/home/rmtp");
		}

		putResourceSrc(view);

		return view;
	}
}
